<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>generator函数-异步请求同步化</title>
  <script src="./js/jquery.js"></script>
  <script>
    const baseURL = 'http://47.94.46.113:8888';
    function findAll() {
      return $.ajax({
        url: baseURL + '/index/category/findAll',
        method: 'get',
        success(res) {
          // 第二次调用.next()方法，传递的实参
          // 将是第一次状态的结束数据
          // 也是第二次状态的入口数据
          gen.next(res)
        }
      })
    }

    function* genFun() {
      let result = yield findAll()

      console.table(result.data);
      yield '结束'
    }

    let gen = genFun();
    gen.next();
  </script>
</head>

<body>

</body>

</html>